
var _util = require('util/util.js');
const { getServerURL, request } = require('../util/util');

var _catalog_service = {
    getProductByCategoryId: function (id, resolve, reject) {
        _util.request({
            url: _util.getServerURL('catalog/categories/' + id + '/products'),
            method: "GET",
            success: resolve,
            error: reject,

        });
    },
    getProductList: function (id, resolve, reject) {
        _util.request({
            url: _util.getServerURL('catalog/categories/' + id + '/products'),
            method: "GET",
            success: resolve,
            error: reject,

        });
    },
    getItemList: function (id, resolve, reject) {
        _util.request({
            url: _util.getServerURL('catalog/products/' + id + '/items'),
            success: resolve,
            error: reject
        });
    },
    getItem: function (id, resolve, reject) {
        _util.request({
            url: _util.getServerURL('catalog/products/items/' + id),
            success: resolve,
            error: reject
        });
    },
    searchProduct: function(keyword,resolve,reject){
        _util.request({
            url: _util.getServerURL('catalog/search_products'),
            data: keyword,
            method: "GET",
            success: resolve,
            error: reject
        });
    },
    getProduct : function(id, resolve, reject){
        _util.request({
            url: _util.getServerURL('catalog/products/' + id),
            success: resolve,
            error: reject
        });
    }

};
module.exports = _catalog_service;